home *** CD-ROM | disk | FTP | other *** search
- {
- ***
-
- ERROR.PAS
- Error-related Routines
- (C)Copyright Gerard Paul Java 1996
-
- Unit Source File
-
-
- This unit contains routines that display the error box and sound the error
- tones, an error message function based on Turbo Pascal's runtime error
- codes, and a routine to abort the program in case of error at startup.
-
- ***
- }
-
- {$A+,B-,F-,I-,N-,R-,S-,V-}
-
- unit Error;
-
- interface
- type
- ErrStrType = string[50];
-
- const
- Instruct = TRUE;
- DontInstruct = FALSE;
-
- var
- ErrBoxAttr,
- ErrMsgAttr: byte;
-
- procedure ErrSound;
- procedure ErrBox(ErrMsg,ContMsg : ErrStrType;
- Instruc : boolean);
- procedure ErrAbort(ErrMsg: string);
- function ErrMsg(Code: word): ErrStrType;
-
- implementation
- uses
- Crt,
- Instruc,
- ScreenRt,
- SysRt;
-
-
- {--------------------------------------------------------------------------
- ErrSound: Sounds error tones.
- --------------------------------------------------------------------------}
-
- procedure ErrSound;
- begin
- Sound(900);Delay(60); { Sound error tones. }
- Sound(500);Delay(60);
- NoSound;
- end;
-
-
- {---------------------------------------------------------------------------
- ErrBox: Displays an error box and sounds the error tones.
- ---------------------------------------------------------------------------}
-
- procedure ErrBox(ErrMsg,ContMsg : ErrStrType;
- Instruc : boolean);
- begin
- Window(1,1,80,25);
-
- if Instruc then
- JustSeeBox;
-
- TextAttr := ErrBoxAttr;
- DrawBox(14,11,67,14,DoubleLine); { Draw red box. }
- Window(16,12,73,14); { Set new window. }
- TextAttr := ErrMsgAttr;Writeln(ErrMsg); { Write messages. }
- TextColor(15);Write(ContMsg);
- ErrSound;
- end; { proc }
-
-
- {----------------------------------------------------------------------------
- ErrAbort: Displays an error message and terminates the program after issuing
- error tones and Esc is pressed.
- ----------------------------------------------------------------------------}
-
- procedure ErrAbort(ErrMsg: string);
- begin { proc }
- ErrBox(ErrMsg,'Press Esc to abort',DontInstruct);
- repeat until GetKeyNoExt = Esc;
- TerminateProg(1);
- end; { proc }
-
- function ErrMsg(Code: word): ErrStrType;
- var
- ErrorMessage: ErrStrType;
- ErrCode: string[2];
-
- begin
- case Code of
- 2: ErrorMessage := 'file not found';
- 3: ErrorMessage := 'path not found';
- 4: ErrorMessage := 'too many open files';
- 5: ErrorMessage := 'access to file denied';
- 101: ErrorMessage := 'disk full';
- 150: ErrorMessage := 'disk write-protected';
- 151: ErrorMessage := 'unknown unit';
- 152: ErrorMessage := 'drive not ready';
- 154: ErrorMessage := 'CRC error in data';
- 156: ErrorMessage := 'disk seek error';
- 157: ErrorMessage := 'unknown media type';
- 158: ErrorMessage := 'sector not found';
- 159: ErrorMessage := 'printer out of paper';
- 160: ErrorMessage := 'device write fault';
- 161: ErrorMessage := 'device read fault';
- 162: ErrorMessage := 'hardware failure';
- else
- begin
- Str(Code,ErrCode);
- ErrorMessage := 'code '+ErrCode;
- end;
- end;
-
- ErrMsg := 'Error: '+ErrorMessage;
- end;
-
- end.
-